/// <reference name="MicrosoftAjax.debug.js" />

Type.registerNamespace("BM");

// Addition object

BM.Addition = function(item, additionNode) {
    ///	<summary locid="T:J#BM.Addition">
    ///		This is an abstract constructor for MForm items' addition objects
    /// The item contains an array of addition objects, each of them may react on certain item events.
    /// When item is loaded the load method of an addition object is run, when item is unloaded the unload method occurs
    ///	</summary>
    ///	<param name="item" type="MItem">
    ///		the item that the addition object is bound to
    ///	</param>
    ///	<param name="additionNode" type="Sys.UI.DomElement" domElement="true">
    ///		a DOM element that contains addition data
    ///	</param>
    /// <field name="item" Type="MItem">
    ///     The MForm item originally passed to the addition.
    /// </field>
    /// <field name="additionNode" type="Sys.UI.DomElement" domElement="true">
    ///     A DOM node that contains addition data
    /// </field>
    ///	<returns type="BM.Addition" />
    BM.Addition.initializeBase(this, []);
    this.item = item;
    this.item.addLoading(Function.createDelegate(this, this.load));
    this.item.addUnloading(Function.createDelegate(this, this.unload));
    this.additionNode = additionNode;
}

BM.Addition.prototype = {

    load: function() {
        ///	<summary>        
        ///		this method is invoked during item load
        ///	</summary>        
    },

    unload: function() {
        ///	<summary>        
        ///		this method is invoked during item unload
        ///	</summary>
    },

    getItem: function() {
        ///	<summary>        
        ///		returns the item bound to the constraint
        ///	</summary>
        ///	<returns type="MItem" />        
        return this.item;
    },

    getValue: function() {
        ///	<summary>        
        ///		returns items' value
        ///	</summary>
        ///	<returns type="String" />        
        return this.item.getValue();
    },

    getInfoText: function() {
        /// <returns type="String" mayBeNull="true" >
        /// gets the attached informative text about the addition
        /// </returns>
        if (this.infoText == null) {
            this.infoText = this.additionNode.getAttribute('infoText');
        }

        return this.infoText;
    },

    appendDescription: function(node) {
        ///	<summary>        
        ///		adds data to a node, that displays item description
        ///	</summary>
        ///	<param name="node" type="Sys.UI.DomElement" domElement="true">
        ///		A node that displays item description
        ///	</param>
        var infoText = this.getInfoText();
        if (infoText != null) {
            var ct = BM.NodeBuilder.createDiv(node, "Constraint");
            BM.NodeBuilder.createSpan(ct, 'Value', infoText);
        }
    }
}

BM.Addition.registerClass("BM.Addition", Sys.Component);

